import type { Module } from 'vuex'
import type { LoginInfo, RootStateTypes } from '../interface'
import { assignOwnProp } from '@jsjn/utils'

const loginInfo: Module<LoginInfo, RootStateTypes> = {
    namespaced: true,
    state() {
        return {
            access_token: '',
            refresh_token: '',
            token_type: '',
            expires_in: '',
            scope: '',
            expiration_time: 0
        }
    },
    mutations: {
        // 全量赋值
        setLoginInfo(state, data: LoginInfo) {
            const currentState = JSON.stringify(state)
            const nextState = JSON.stringify(data)
            if (currentState === nextState) return
            assignOwnProp(state, data)
        }
    }
}

export default loginInfo
